<?php
// +----------------------------------------------------------------------
// | HisiPHP框架[基于ThinkPHP5.1开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2021 http://www.HisiPHP.com
// +----------------------------------------------------------------------
// | HisiPHP承诺基础框架永久免费开源，您可用于学习和商用，但必须保留软件版权信息。
// +----------------------------------------------------------------------
// | Author: 橘子俊 <364666827@qq.com>，开发者QQ群：50304283
// +----------------------------------------------------------------------

namespace app\system\admin;

use think\Db;

/**
 * 返利管理控制器
 * @package app\system\admin
 */
class Rebate extends Admin
{
    /**
     * 直接返利-列表
     */
    public function ztfl(){
        $list = Db::name('czfljl')->where("fl_type != 3")->paginate(20)->each(function($item, $key){
            $item['dlname'] = Db::name("daili")->where("id = '{$item['dl_id']}'")->value("dlname");
            $item['czdlname'] = Db::name("daili")->where("id = '{$item['czjl_id']}'")->value("dlname");
            return $item;
        });
        $this->assign('list', $list);
        return $this->fetch();
    }
    
    /**
     * 越级返利-列表
     */
    public function jtfl(){
        $list = Db::name('czfljl')->where("fl_type = 3")->paginate(20)->each(function($item, $key){
            $item['dlname'] = Db::name("daili")->where("id = '{$item['dl_id']}'")->value("dlname");;
            $item['czdlname'] = Db::name("daili")->where("id = '{$item['czjl_id']}'")->value("dlname");
            return $item;
        });
        $this->assign('list', $list);
        return $this->fetch();
    }
    
    /**
     * 采购返利
     */
    public function cgfl(){
        $list = Db::name('cgfl')->paginate(20)->each(function($item, $key){
            $item['dlname'] = Db::name("daili")->where("id = '{$item['dl_id']}'")->value("dlname");
            $cgdlid = Db::name("cgjl")->where("id = '{$item['cgjl_id']}'")->value("dl_id");
            $item['cgdlname'] = Db::name("daili")->where("id = '{$cgdlid}'")->value("dlname");
            return $item;
        });
        $fl_type = array('','平级','越级','下级');
        $this->assign('fl_type', $fl_type);
        $this->assign('list', $list);
        return $this->fetch();
    }
}
